﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Xml;

namespace TemplateH4
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.lbUser.Text = (string)Session["UserName"];

        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            
        }

        protected void Login1_LoggedIn(object sender, EventArgs e)
        {
            string UserName = this.Login1.UserName;
            
            Session["IsLogin"] = 1;
            Session["UserName"] = UserName;

            MembershipUser User = Membership.GetUser(UserName);
            Guid UserID = (Guid)User.ProviderUserKey;
            Session.Add("UserId", UserID);
            
            //this.lbUser.Text = (string) Session["UserName"];
            //if (Page.PreviousPage != null)
            //    Response.Redirect(Page.PreviousPage);
            //else
                Response.Redirect("~/Default.aspx");
        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {

        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            String thm;
            thm = (string)Session["themeSelected"];
            if (thm != null)
            {
                Page.Theme = thm;
            }
            else
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(Server.MapPath("~/config.xml"));
                XmlNode root = doc.DocumentElement;
                String theme = root.SelectSingleNode("theme").ChildNodes[0].Value.Trim();
                Session.Add("themeSelected", theme);
                Page.Theme = theme;
            }

        }
    }
}
